package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.HighLeverFaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xu_jiaHui on 2018/3/24.
 */
@Controller
@RequestMapping("/rds_highLeverFault")
public class HighLeverFaultController {
    @Resource
    private HighLeverFaultService highLeverFaultService;

    @RequestMapping(value = "/getHighLeverReportFault4DT")
    @ResponseBody
    public DTResponseDto getHighLeverReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = highLeverFaultService.getHighLeverReportFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getHighLeverInfo2Fault")
    @ResponseBody
    public JsonMsgDto getHighLeverInfo2Fault(Integer highLeverId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverFaultService.getHighLeverInfo2Fault(highLeverId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getHighLeverFaultInfo2Fault")
    @ResponseBody
    public JsonMsgDto getHighLeverFaultInfo2Fault(Integer highLeverId, Integer highLeverFaultId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverFaultService.getHighLeverFaultInfo2Fault(highLeverId, highLeverFaultId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateHighLeverFault")
    @ResponseBody
    public JsonMsgDto updateHighLeverFault(Integer highLeverFaultId, Integer highLeverFaultLevel, Integer highLeverFaultType, String highLeverFaultPhoto, String highLeverFaultReason, Double highLeverMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverFaultService.updateHighLeverFault(highLeverFaultId, highLeverFaultLevel, highLeverFaultType, highLeverFaultPhoto, highLeverFaultReason, highLeverMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getHighLeverFaultIsReport")
    @ResponseBody
    public JsonMsgDto getHighLeverFaultIsReport(Integer highLeverId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverFaultService.getHighLeverFaultIsReport(highLeverId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/reportHighLeverFault")
    @ResponseBody
    public JsonMsgDto reportHighLeverFault(Integer highLeverId, Integer highLeverFaultCreatorId, Integer highLeverFaultLevel, Integer highLeverFaultType,
                                           String highLeverFaultPhoto, String highLeverFaultReason, Double highLeverMoney, Integer highLeverOrgId, Integer highLeverMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            highLeverFaultService.reportHighLeverFault(highLeverId, highLeverFaultCreatorId, highLeverFaultLevel, highLeverFaultType,
                    highLeverFaultPhoto, highLeverFaultReason, highLeverMoney, highLeverOrgId, highLeverMainOrgId);
            //为空是app端作判断
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteHighLeverFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteHighLeverFaultByIds(String highLeverFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverFaultService.deleteHighLeverFaultByIds(highLeverFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getHighLeverCoordinate4Map")
    @ResponseBody
    public JsonMsgDto getHighLeverCoordinate4Map(Integer orgId, Integer actorId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverFaultService.getHighLeverCoordinate4Map(orgId, actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getHighLeverByXY")
    @ResponseBody
    public JsonMsgDto getHighLeverByXY(String longitude, String latitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverFaultService.getHighLeverByXY(longitude, latitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getHighLeverFaultReport4DT")
    @ResponseBody
    public DTResponseDto getHighLeverFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId, String highLeverRoadName, String highLeverStartRoad, String highLeverEndRoad) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = highLeverFaultService.getHighLeverFaultReport4DT(dtRequestDto, actorId, orgId, highLeverRoadName, highLeverStartRoad, highLeverEndRoad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverFaultService.getStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverFaultService.getSectionByStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/getHighLeverFaultList4App")
    @ResponseBody
    public JsonMsgDto getHighLeverFaultList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size)
            throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverFaultService.getHighLeverFaultList4App(orgId, actorIds, faultStatus, count, size));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }
}

